﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Xml;
using System.Reflection;
using System.Globalization;
using System.Threading;

namespace QLDBHYT
{
    public class Modules
    {

        public static bool  UpdateFlag()
        {
             dbConnection conn;
             conn = new dbConnection();
            string query = string.Format("UPDATE NT_KIEMTRA SET "
            + "flag = 0 where username = @username and error = 0");
                      
            SqlParameter[] sqlParameters = new SqlParameter[1];
            sqlParameters[0] = new SqlParameter("@username", SqlDbType.NVarChar);
            sqlParameters[0].Value = Properties.Settings.Default.UserName;
            conn.executeInsertQuery(query, sqlParameters);
            return true;
        }
        public static DataTable  GetKy()
        {
            dbConnection conn;
            conn = new dbConnection();
            string query = string.Format("select thang,nam from nt_ky where ky = 1");

            SqlParameter[] sqlParameters = new SqlParameter[0];
            return  conn.executeSelectQuery(query, sqlParameters);
            
        }
        public static void SendKey(Form frm, KeyEventArgs e)
        {

            try
            {

                if (((((e.KeyCode == Keys.Return) & !e.Alt) & !e.Control) & !e.Shift) && !((frm.ActiveControl.Parent is C1.Win.C1FlexGrid.C1FlexGrid) | (frm.ActiveControl is C1.Win.C1FlexGrid.C1FlexGrid)))
                {

                    if (frm.GetNextControl(frm.ActiveControl, true) != null)
                    {
                        SendKeys.Send("{TAB}");
                    }
                    else
                    {
                        while (frm.GetNextControl(frm.ActiveControl, true) == null)
                        {

                            if (!frm.GetNextControl(frm.ActiveControl, true).Enabled)
                            {
                                frm.ActiveControl = frm.GetNextControl(frm.ActiveControl, true);
                            }
                            else
                            {
                                if (!frm.GetNextControl(frm.ActiveControl, true).Visible)
                                {
                                    if (frm.GetNextControl(frm.ActiveControl, true) is TabPage)
                                    {
                                        frm.ActiveControl = frm.GetNextControl(frm.ActiveControl, true);
                                        return;
                                    }
                                    frm.ActiveControl = frm.GetNextControl(frm.ActiveControl, true);
                                    continue;
                                }
                                if (frm.GetNextControl(frm.ActiveControl, true) is GroupBox)
                                {
                                    frm.GetNextControl(frm.ActiveControl, true).Focus();
                                    frm.GetNextControl(frm.ActiveControl, true).Focus();
                                    continue;
                                }
                                if (frm.GetNextControl(frm.ActiveControl, true) is TabControl)
                                {
                                    frm.ActiveControl = frm.GetNextControl(frm.ActiveControl, true);
                                    continue;
                                }
                                if (frm.GetNextControl(frm.ActiveControl, true) is TabPage)
                                {
                                    frm.ActiveControl = frm.GetNextControl(frm.ActiveControl, true);
                                    continue;
                                }
                                if (frm.GetNextControl(frm.ActiveControl, true) is RadioButton)
                                {
                                    if (frm.ActiveControl is RadioButton)
                                    {
                                        SendKeys.Send("{TAB}");
                                    }
                                    else
                                    {
                                        frm.ActiveControl = frm.GetNextControl(frm.ActiveControl, true);
                                    }
                                    return;
                                }
                                if (frm.GetNextControl(frm.ActiveControl, true) is Label)
                                {
                                    frm.GetNextControl(frm.ActiveControl, true).Focus();
                                    frm.GetNextControl(frm.ActiveControl, true).Focus();
                                }
                                else
                                {
                                    frm.GetNextControl(frm.ActiveControl, true).Focus();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exception1)
            {

                Exception exception = exception1;
                throw exception;

            }
        }
        
    }
}
